<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 部门  -->
<title>department_index</title>
<script type="text/javascript" src="<%=request.getContextPath() %>/assets/scripts/jquery-1.9.1.js"></script>
<link type="text/css" href="<%=request.getContextPath() %>/assets/style/admin.css" rel="stylesheet" />
</head>
<body>
<div class="page">
	
	<h1>department index</h1>
	<a href="department.action?_method=editNew">add</a>

	<table class="admin_table">
		<thead>
			<tr>
				<th>index</th>
				<th>name</th>
				<th>operation</th>
			</tr>
		</thead>
		<tbody>
			<s:iterator value="dmList" status="status" id="instance">
				<tr>
					<td>${ instance.id}</td>
					<td>${ instance.name}</td>
					<td><a href="javascript:edit('${instance.id}', '${instance.name}');">edit</a>&nbsp;&nbsp;<a href="javascript:delete_dep('${instance.id}');">delete</a></td>
				</tr>
			</s:iterator>
		</tbody>
	</table>
	
	<s:form action="%{request.getContextPath}/department.action" id="depForm">
		<s:hidden name="_method" id="_method" />
		<s:hidden name="id" id="id" />
		<s:hidden name="departmentName" id="departmentName" />
	</s:form>
</div>
<script type="text/javascript">
	function edit(id, name) {
		$('#id').val(id);
		$('#_method').val('edit');
		$("#depForm").attr('method', 'get');
		$('#departmentName').val(name);
		$('#depForm').submit();
	}
	
	function delete_dep(id) {
		
		$('#id').val(id);
		alert(id);
		$('#_method').val('delete');
		$("#depForm").attr('method', 'post');
		$('#depForm').submit();
	}
</script>
</body>
</html>